package org.point.dao.impl;

import java.io.Serializable;
import java.util.HashMap;
import java.util.Hashtable;
import java.util.List;
import java.util.Map;

import org.point.common.dao.impl.BaseDaoImpl;
import org.point.common.util.DoPage;
import org.point.dao.CreditsTypeDao;import org.point.domain.CreditsType;
import org.springframework.stereotype.Repository;

/**
 * 
 * @ClassName: CreditsTypeDaoImpl  
 * @Description: TODO(积分规则分类数据实现类)  
 * @author Kenny_Z' szqiuk@gmail.com
 * @date 2016年10月23日 下午3:39:53  
 *
 */
@Repository("creditsTypeDao")
public class CreditsTypeDaoImpl extends BaseDaoImpl<CreditsType, Serializable> implements CreditsTypeDao {

	/**
	 * 利用反射，获取mapper.xml的namespace
	 * <p>Title: </p>  
	 * <p>Description: </p>
	 */
	public CreditsTypeDaoImpl() {
		namespace = super.getNamespace();
	}

	// 根据会员单位查询积分规则分类信息列表
	public static final String SQLID_FINDCTFORMEM = "find_CT_For_Mem";
	public static final String SQLID_FINDCTFORMEMPAGE = "find_CT_For_Mem_Page";
	// 根据会员单位查询积分规则分类记录数
	public static final String SQLID_FINDCTFORMEMCOUNT = "find_CT_For_Mem_Count";
	// 会员单位新增积分规则分类信息
	public static final String SQLID_INSERTCT = "insert_CT";
	// 修改积分规则分类状态
	public static final String SQLID_UPDSTATUS = "upd_Status";
	// 修改积分规则分类删除状态
	public static final String SQLID_UPDDELFLAG = "upd_delflag";
	// 根据积分规则分类索引ID查询积分规则详细信息
	public static final String SQLID_SEARCHFORCT = "searchForCT";
	//批量删除积分规则分类
	private static final String SQLID_DELETECTS = "del_cts";
	
	private static final String SQLID_DELETECTBYID = "del_ct_id";
	
	private static final String SQLID_SEARCHSELECTEDINFO = "selected_info";
	
	public List<CreditsType> findCTForMem(Map<String, Object> map) {
		List<CreditsType> records;
		try {
			records = getSqlSession().selectList(namespace + SQLID_FINDCTFORMEM, map);
		} catch (Exception e) {
			throw new RuntimeException("积分规则分类查询数据库错误！", e);
		}
		return records;
	}

	public List<CreditsType> findCTForMem(DoPage<CreditsType> page) {
		List<CreditsType> records = null;
		try {
			records = getSqlSession().selectList(namespace + SQLID_FINDCTFORMEMPAGE, page);
		} catch (Exception e) {
			e.printStackTrace();
			// throw new RuntimeException("积分规则分类查询数据库错误！", e);
		}
		return records;
	}
	
	public Integer countCTForMem(DoPage<CreditsType> page) {
		Integer result = 0;
		try {
			result = getSqlSession().selectOne(namespace + SQLID_FINDCTFORMEMCOUNT, page);
		} catch (Exception e) {
			e.printStackTrace();
			// throw new RuntimeException("积分规则分类查询记录错误！", e);
		}
		return result;
	}
	
	public Integer insertCT(CreditsType record) {
		Integer result = 0;
		try {
			result = getSqlSession().insert(namespace + SQLID_INSERTCT, record);
		} catch (Exception e) {
			throw new RuntimeException("积分规则分类新增错误！", e);
		}
		return result;
	}

	public Integer updStatus(Map<String, Object> map) {
		Integer result = 0;
		try {
			result = getSqlSession().update(namespace + SQLID_UPDSTATUS, map);
		} catch (Exception e) {
			throw new RuntimeException("积分规则分类新增错误！", e);
		}
		return result;
	}

	public Integer updDelflag(Map<String, Object> map) {
		Integer result = 0;
		try {
			result = getSqlSession().update(namespace + SQLID_UPDDELFLAG, map);
		} catch (Exception e) {
			throw new RuntimeException("积分规则分类修改删除状态错误！", e);
		}
		return result;
	}

	public CreditsType searchForCT(Map<String, Object> map) {
		CreditsType record = null;
		try {
			record = getSqlSession().selectOne(namespace + SQLID_SEARCHFORCT, map);
		} catch (Exception e) {
			throw new RuntimeException("积分规则分类查询错误！", e);
		}
		return record;
	}

	public Integer deleteCTs(Map<String, Object> map) {
		Integer result = 0;
		try {
			result = getSqlSession().update(namespace + SQLID_DELETECTS, map);
		} catch (Exception e) {
			throw new RuntimeException("积分规则修改删除错误！", e);
		}
		return result;
	}

	public Integer delCTbyId(String id) {
		Integer result = 0;
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("id", id);
		try {
			result = getSqlSession().update(namespace + SQLID_DELETECTBYID, map);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return result;
	}

	public List<Hashtable<Object, Object>> searchSelectedInfo() {
		List<Hashtable<Object, Object>> record = null;
		try {
			record = getSqlSession().selectList(namespace + SQLID_SEARCHSELECTEDINFO);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return record;
	}

}
